package com.example.casper.jnuexperiment2025;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class ImageViewActivity extends AppCompatActivity {
    private Button buttonPrevious, buttonNext;
    private ImageView imageViewFunny;
    private final int[] imageIDArray = {R.drawable.funny_1, R.drawable.funny_2,
            R.drawable.funny_3, R.drawable.funny_4, R.drawable.funny_5,
            R.drawable.funny_6
    };
    private int imageIDArrayCurrentIndex = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_image_view);
        /*ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });*/

        buttonPrevious = findViewById(R.id.button_previous);
        buttonNext = findViewById(R.id.button_next); 
        imageViewFunny = findViewById(R.id.image_view_funny);

        imageViewFunny.setImageResource(imageIDArray[imageIDArrayCurrentIndex]);

        buttonPrevious.setOnClickListener(view -> {
            imageIDArrayCurrentIndex--;
            if (imageIDArrayCurrentIndex < 0) {
                imageIDArrayCurrentIndex = imageIDArray.length - 1; 
            }
            imageViewFunny.setImageResource(imageIDArray[imageIDArrayCurrentIndex]);
        });

        buttonNext.setOnClickListener(view -> {
            imageIDArrayCurrentIndex++;
            if (imageIDArrayCurrentIndex >= imageIDArray.length) {
                imageIDArrayCurrentIndex = 0; 
            }
            imageViewFunny.setImageResource(imageIDArray[imageIDArrayCurrentIndex]);
        });
    }
}